import apis from "../http/apis"


export default {
    namespaced: true,
    state: {
        salesmansDate: [],
        salesmansId: [],
    },

    actions: {
        //新增销售员
        async addSalesmans(context, salesmans) {
            const { data } = await apis.salesmans.addSalesmans({
                ...salesmans

                //...salesmans
            });
            if (data.status) {
                console.log('新增成功');
                context.dispatch('getSalesmans')
                context.state.salesmansDate = data.data
            }
        },
        // 获取销售员
        async getSalesmans(context) {

            const { data } = await apis.salesmans.getSalesmans();
            if (data.status) {
                context.state.salesmansDate = data.data
            }
        },
        //获取销售员id
        async getSalesmansById(context, salesmans) {
            const { data } = await apis.salesmans.getSalesmansById(...salesmans)
            if (data.status) {
                context.state.salesmansId = data.data[0]
                return data.data[0]
            }
        },

        //修改销售员
        async updateSalesmans(context, newsalesmans) {
            const { data } = await apis.salesmans.updateSalesmans(newsalesmans)
            if (data.status) {
                console.log('修改成功');
            }
        },

        //删除销售员
        async deleteSalesmans(context, id) {
            const { data } = await apis.salesmans.deleteSalesmans({ _id: id })
            console.log(data);
            if (data.status) {
                context.dispatch('getSalesmans')
            }

        }

    },
    getters: {

    },

}

